package com.huaxin.device.dto.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;

/**
 * 设备状态枚举
 */
public enum DeviceStatus implements BaseCodeEnum<String> {
    ONLINE("online", "在线"),
    OFFLINE("offline", "离线"),
    FAILURE("failure", "故障"),
    DEACTIVATE("deactivate", "停用"),
    SCRAP("scrap", "报废"),
    MONITORING("monitoring", "监控");

    @EnumValue
    private final String code;
    private final String displayName;

    DeviceStatus(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static DeviceStatus of(String code) {
        for (DeviceStatus type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        return null;
    }

    public static boolean isValid(String code) {
        return of(code) != null;
    }
}
